package edu.fiu.cis.personalize.server.graph;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicInteger;

import edu.fiu.cis.personalize.server.graph.store.CountingConcMap;
import edu.fiu.cis.personalize.server.graph.store.NodeEdges;

//A User object has two attributes "userName" and "userId"
@SuppressWarnings("serial")
public class User extends Node implements Serializable {
	private static final int EPSILON = 0;
	private CountingConcMap clicksDocument = new CountingConcMap();
	private CountingConcMap submitsQuery = new CountingConcMap();
	
	public CountingConcMap getClicksDocument() {
		return clicksDocument;
	}
	
	public CountingConcMap getSubmitsQuery() {
		return submitsQuery;
	}

	/**
	 * 
	 * @param userName
	 */
	public User(int id, String userName) {
		super(id, userName);
	}

	/**
	 * 
	 * @return The user name
	 */
	public String getUserName() {
		return getStringKey();
	}

	public String toString() {
		return getStringKey();
	}

	@Override
	public NodeType getType() {
		return NodeType.USER;
	}

	public int submitsQuery(Query q) {
		return submitsQuery.incrementCount(q.getId());
	}

	public int getSubmitQueryCount(Query q) {
		return submitsQuery.get(q.getId()).get();
	}

	public int clicksDocument(Document d) {
		return clicksDocument.incrementCount(d.getId());

	}

	public double getAverageNumQueries() {
		double c = 0;
		for (AtomicInteger i : submitsQuery.values()) {
			c += i.get();
		}
		return c*1.0/submitsQuery.size();
	}

	public double getDocClickCount(Document d) {
		return clicksDocument.get(d.getId()).get();
	}

	public double getNumDocsClicked() {
		return clicksDocument.keySet().size();
	}

	public double getTotalClicks() {
		int c = 0;
		for (AtomicInteger i : clicksDocument.values()) {
			c += i.get();
		}
		return c;
	}

	public static User create(int id, String uname, NodeEdges nodeEdges,double rank, CountingConcMap cd, CountingConcMap sq) {
		User user = new User(id,uname);
		user.edges = nodeEdges;
		user.rank = rank;
		user.clicksDocument = cd;
		user.submitsQuery = sq;
		return user;
	}
	
	

}